package com.hex.ds.hdrs.agent.controller;

import com.hex.bigdata.hbda.base.Page;
import com.hex.ds.hdrs.agent.po.AgentHeartbeatLog;
import com.hex.ds.hdrs.agent.service.AgentHeartbeatLogService;
import com.hex.ds.hdrs.agent.vo.AgentHeartbeatLogVo;
import com.hex.ds.hdrs.agent.vo.AvgInfoChart;
import com.hex.ds.hdrs.agent.vo.CpuInfoChart;
import com.hex.ds.hdrs.agent.vo.MemoryInfoVo;
import com.hex.ds.hdrs.common.page.PageData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 节点心跳日志 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2020-11-26
 */
@RestController
@RequestMapping("/api/agentHeartbeatLog")
@Slf4j
@Api("日志管理")
public class AgentHeartbeatLogController {

    @Autowired
    private AgentHeartbeatLogService agentHeartbeatLogService;

    /**
     * @param page
     * @return
     */
    @GetMapping("/selectPages")
    @ApiOperation("查询心跳日志数据")
    public ResponseEntity<Object> queryHeartbeatLog(AgentHeartbeatLogVo agentHeartbeatLog, Page page) {
        log.info("进入了【AgentHeartbeatLogController】的queryHeartbeatLog方法");
        PageData pageData = new PageData(this.agentHeartbeatLogService.queryHeartbeatLog(agentHeartbeatLog, page), page);
        return new ResponseEntity<>(pageData, HttpStatus.OK);
    }

    /**
     * @param pkId
     * @return
     */
    @GetMapping("/getHeartbeatDetail")
    @ApiOperation("查询心跳日志详细数据")
    public ResponseEntity<Object> getHeartbeatDetail(@RequestParam String pkId) {
        log.info("进入了AgentHeartbeatLog的getHeartbeatDetail【{}】", pkId);
        AgentHeartbeatLog agentHeartbeatLog = this.agentHeartbeatLogService.getHeartbeatDetail(pkId);
        return new ResponseEntity<>(agentHeartbeatLog, HttpStatus.OK);
    }


    /**
     * 查询某节点的磁盘信息
     *
     * @param agentCode
     * @return
     */
    @GetMapping("/selectDiscByCode")
    public ResponseEntity<Object> qryDicoInfo(@RequestParam("agentCode") String agentCode) {
        String dicoInfo = agentHeartbeatLogService.qryDicoInfo(agentCode);
        return new ResponseEntity<>(dicoInfo, HttpStatus.OK);
    }

    /**
     * CPU使用率折线图
     *
     * @param cpuTime
     * @return
     */
    @GetMapping("/cpuChartData")
    public ResponseEntity<Object> qryCpuInfo(@RequestParam("cpuTime") String cpuTime,
                                             @RequestParam("agentCode") String agentCode) {
        CpuInfoChart cpuInfoChart = agentHeartbeatLogService.qryCpuChartData(cpuTime, agentCode);
        return new ResponseEntity<>(cpuInfoChart, HttpStatus.OK);
    }

    /**
     * RAM使用率折线图
     *
     * @param ramTime
     * @return
     */
    @GetMapping("/ramChartData")
    public ResponseEntity<Object> qryRamInfo(@RequestParam("ramTime") String ramTime,
                                             @RequestParam("agentCode") String agentCode) {
        CpuInfoChart ramInfoChart = agentHeartbeatLogService.qryRamChartData(ramTime, agentCode);
        return new ResponseEntity<>(ramInfoChart, HttpStatus.OK);
    }

    /**
     * 平均负载折线图
     *
     * @param avgTime
     * @return
     */
    @GetMapping("/avgChartData")
    public ResponseEntity<Object> qryAvgInfo(@RequestParam("avgTime") String avgTime,
                                             @RequestParam("agentCode") String agentCode) {
        AvgInfoChart avgInfoChart = agentHeartbeatLogService.qryAvgChartData(avgTime, agentCode);
        return new ResponseEntity<>(avgInfoChart, HttpStatus.OK);
    }

    /**
     * 磁盘使用率折线图
     *
     * @param fileSysTime
     * @return
     */
    @GetMapping("/getFileSysInfo")
    public ResponseEntity<Object> getFileSysInfo(@RequestParam("fileSysTime") String fileSysTime,
                                                 @RequestParam("agentCode") String agentCode) {
        CpuInfoChart ramInfoChart = agentHeartbeatLogService.getFileSysInfo(fileSysTime, agentCode);
        return new ResponseEntity<>(ramInfoChart, HttpStatus.OK);
    }


    /**
     * 获取一条磁盘数据
     *
     * @param agentCode
     * @return
     */
    @GetMapping("/getMemoryObjInfoList")
    public ResponseEntity<Object> getMemoryObjInfoList(@RequestParam("agentCode") String agentCode) {
        List<MemoryInfoVo> memoryInfoVo = agentHeartbeatLogService.getMemoryObjInfoList(agentCode);
        return new ResponseEntity<>(memoryInfoVo, HttpStatus.OK);
    }
}
